<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Session;
use \think\Db;
class Formpostreply extends Common
{
	
  public function addpostreply(){
    $this->assign('postid',input('postid'));
    $this->assign('commentid',input('commentid'));
    return $this->fetch();
  }

  public function editpostreply(){

    $reply = Db::name('postreply')->where('reply_id',input('replyid'))->find();
    $this->assign('postreply',$reply);
    return $this->fetch();

  }

  public function add(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'comment_id'=>input('commentid'),
          'user_id'=>0,
          'reply_content'=>input('content'),
          'reply_time'=>date('Y-m-d H:i:s'),
          'scan_status'=>1,
          'reply_status'=>1,
        ];
        $res=Db::name('postreply')->insert($data);
        if ($res){
          $this->success("回复成功",url('community/postreply',['commentid'=>input('commentid')]));
        }
        else {
          $this->error("回复失败");
        }
      }
  }



  public function edit(){
    $info = '';
     if(request()->isPost()){  
        $data=[
          'reply_content'=>input('content'),
        ];
        $res=Db::name('postreply')->where('reply_id',input('replyid'))->update($data);
        if ($res!==false){
          $this->success("修改评论成功",url('community/postreply',['commentid'=>input('commentid')]));
        }
        else {
          $this->error("修改失败");
        }
      }
  }

  public function delete(){
    $res = Db::name('postreply')->where('reply_id',input('replyid'))->update(['reply_status'=>input('statu')]);
    if($res===false){
        $this->error("处理失败");
    }
    $this->redirect(url('community/postreply',['commentid'=>input('commentid')]));
  }

  
}